/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—07—23
 * Time: 9:10
 */
public class HashBuck {
    static class Node {
        public int key;
        public int val;
        public Node next;

        public Node(int key, int val) {
            this.key = key;
            this.val = val;
        }
    }

    public Node[] array;
    public int usedSize;//记录当前哈希桶中有效数据的个数

    public static final float DEFAULT_LOAD_FACTOR = 0.75F;
    public HashBuck() {
        this.array = new Node[10];
        this.usedSize = 0;
    }
    /**
     * @param key:
     * @param val:
     * @return int
     * @description 存储key val
     */
    public void put (int key, int val) {
        Node node = new Node(key,val);
        int index = key % array.length;
        Node cur = array[index];
        while (cur != null) {
            if(cur.key == key) {
                cur.val = val;
                return;
            }
            cur = cur.next;
        }
        //头插法
        node.next = array[index];
        array[index] = node;
        usedSize++;
        //检查负载因子
        if(loadFactor() >= DEFAULT_LOAD_FACTOR) {
            //进行扩容
            grow();
        }
    }

    private float loadFactor() {
        return usedSize*1.0f / array.length;
    }
    private void grow (int key ,int val) {
        Node[] newArray = new Node[2*array.length];
        //重新的哈希
        /**
         * 1.遍历数组的每个元素的链表
         * 2.每遍历到一个节点，就重写哈希 key%len
         * 3.进行头插法
         */
        for (int i = 0; i < array.length; i++) {
            Node cur = array[i];
            while (cur != null) {
                int index = cur.key % newArray.length;
                cur.next = newArray[index];
                newArray[index] = cur;
                cur =
            }
        }
        Node node = new Node(key,val);
        int len = key % newArray.length;
        Node cur = newArray[len];
        while (cur != null) {
            if(cur.key == key) {
                cur.val = val;
                return;
            }
            cur = cur.next;
        }

        this.array = newArray;
    }
    /**
     * @param key:
     * @return int
     * @description 通过key值 获取val值
     */
    public int get (int key) {
        int index =
        return key % array.length;
    }
}
